﻿using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace WindowsGame3
{
    public class block2
    {
      
        

      
  
        
       public Texture2D[] defineBlock(GraphicsDevice g, int randomizer, SpriteBatch spriteBatch, SpriteFont font)

        {
           

           
            int[,] shapeL = { 
                                 
                                 {0, 0, 0, 0, 0},  
                                 {0, 0, 1, 0, 0},  
                                 {0, 0, 2, 0, 0},  
                                 {0, 0, 1, 1, 0},  
                                 {0, 0, 0, 0, 0}
                                 
                                 };
           int[,] Shape = shapeL;

          return positionRectangle(Shape, g, spriteBatch, font);


        
        }


        
        public Texture2D[] positionRectangle(int[,] Shape, GraphicsDevice g, SpriteBatch spriteBatch, SpriteFont font)
        {
            int truex = 270;
            int x = truex;
            int y = 0;
            int z = 0;
            int i = 0;
          
            int scale = 30;

            Texture2D[] blocky;
            blocky = new Texture2D[25];

            foreach (int element in Shape)
            {
                

                if (z == 5)
                {
                    // Y is how much to move down after each array dimension is exceeded. We used the height of the rectangle
                    y = y + scale ;
                    // Z once is set to 5, Z will be set to 0 again, holds array dimension.
                    z = 1; // for some reason it wasnt wrapping my array right, had to use 1, will think about later.
                    x = truex; //needed to pass the real value of x origin back to X.
                }
                else
                { 
                    z = z + 1; //Iterate up to track which array dimension we are on.
                }


                x = (x + scale);

                if (element >= 1)
                {
                    blocky[i] = CreateRectangle(Shape, g, spriteBatch, x, y, font, element, scale);
                }
                
               i = i + 1;
            
               
            }
            return blocky;
        }



        public Texture2D CreateRectangle(int[,] Shape, GraphicsDevice g, SpriteBatch spriteBatch, int x, int y, SpriteFont font, int element, int scale )
        {

            Texture2D rectangleTexture = new Texture2D(g, scale, scale, 1, TextureUsage.None, SurfaceFormat.Color);

            Color[] color = new Color[scale * scale];//set the color to the amount of pixels

            for (int i = 0; i < color.Length; i++)//loop through all the colors setting them to whatever values we want
            {
                color[i] = new Color(0, 255, 255, 255);
            }
            Vector2 xy;
            xy.X = x;
            xy.Y = y;
            rectangleTexture.SetData(color);//set the color data on the texture
            spriteBatch.Draw(rectangleTexture, xy , Color.Violet);
            spriteBatch.DrawString(font, element.ToString(), xy, Color.White);
            xy.X = 90;
            
            return rectangleTexture;
        }


    }



}

